<template>
	<view class="container">
		<loading :show="loading_show"></loading>
		<customHead
			title="我的店铺"
			isShowBackArrow
			:titlePaddingLeft="30"
			:placeholder="true"
			navi_background="#fff"
		>
		</customHead>
		<view class="main" v-if="naviHeight">
			<view class="" v-for="(item, index) in firmList" :key="item.id">
				<view class="store_box" :class="[`status${item.isAudit}`, currentFirm.id == item.id? 'currentItem':'']" @click="selectItem(item, index)">
					<view class="currentStore">
						<view class="auditing" v-if="item.isAudit == 1">审核中</view>
						<!-- <view class="success" :class="[currentFirm.id == item.id? 'current':'']" v-if="item.isAudit == 2">{{currentFirm.id == item.id?'使用中':'审核通过'}}</view> -->
						<view class="success" :class="[currentFirm.id == item.id? 'current':'']" v-if="item.isAudit == 2">{{currentFirm.id == item.id?'使用中':'审核通过'}}</view>
						<view class="fail" v-if="item.isAudit == 3">审核未通过</view>
					</view>
					<view class="title" :class="[`audit${item.isAudit}`]">
						<view class="left">
							<text>{{item.exJson.storeName}}</text>
						</view>
						<view class="right" @click.native.stop="editStore(item)" v-if="item.isAudit == 2">
							<view class="icon">
								<u-icon name="edit-pen" size="22" color="#fff"></u-icon>
							</view>
							<text>编辑</text>
						</view>
					</view>
					<view class="content">
						<view class="item">
							<text>{{ `${item.exJson.province} - ${item.exJson.city} - ${item.exJson.district}` }}</text>
						</view>
						<view class="item">
							<text>{{ item.exJson.address }}</text>
							<text>{{ item.exJson.houseNumber }}</text>
						</view>
						<view class="item">
							<text style="padding-right: 6rpx;">{{ item.exJson.name }}</text>
							<text>{{ makeMobile(item.exJson.mobile) }}</text>
							<text v-if="item.isAudit == 2" style="color: #000; font-size: 26rpx;position: absolute;right: 0;">点击切换</text>
						</view>
						<!-- <view class="item">
							<text>{{region}}</text>
						</view>
						<view class="item">
							<text>{{customer}}</text>
							<text>{{phone}}</text>
						</view>
						<view class="item">
							<text>办事处：***（上海区）</text>
						</view> -->
					</view>
				</view>
			</view>
			
			<view class="emptyGoods" v-if="!firmList.length">
				<u-empty
					text="暂无店铺"
					mode="data"
					icon="http://cdn.uviewui.com/uview/empty/data.png"
				>
				</u-empty>
			</view>
		</view>
		<view class="bottom_submit">
			<button class="button _btn_base" @click="gotoAddAstore" :style="{backgroundColor: _temp_themeColor}">
				<u-icon name="plus" bold color="#fff"></u-icon>
				<text>添加店铺</text>
			</button>
		</view>
	</view>
</template>

<script>
	import { auditList } from "@/tools/request/api.js"
	import { mapState, mapActions, mapMutations } from 'vuex'
	import { makeContrast, makeLightColor } from '@/tools/utils/colorful.js'
	export default {
		data() {
			return {
				audit_list: [],
				auditIndex: 0
			};
		},
		onShow () {
			this.getFirmList();
		},
		computed: {
			...mapState('firm_store', ['firmList', 'currentFirm']),
			makeMobile () {
				return function (mobile) {
					mobile = mobile + '';
					let reg = /(\d{3})\d{4}(\d{4})/;
					let tel1 = mobile.replace(reg, "$1****$2")
					return tel1;
				}
			},
			lightColor () {
				let light_color = makeLightColor(this._temp_themeColor, 0.7);
				console.log(light_color, 'light_color')
				return light_color;
			},
			lightColor1 () {
				let light_color = makeLightColor(this._temp_themeColor, 0.9);
				console.log(light_color, 'light_color')
				return light_color;
			}
		},
		methods: {
			...mapActions('firm_store', ['getFirmList', 'updateFirm']),
			...mapMutations('app_store', ['SET_CURRENT_ADDRESS']),
			gotoAddAstore () {
				uni.navigateTo({
					url: '/subpack_my/myStore/addStore/addStore'
				})
			},
			editStore (item) {
				uni.navigateTo({
					url: `/subpack_my/myStore/addStore/addStore?id=${item.id}`
				})
			},
			// 切换店铺
			selectItem (item, index) {
				if (item.isAudit != 2) return;
				if (this.currentFirm.id == item.id) return;
				this.updateFirm(item);
				this.SET_CURRENT_ADDRESS({});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		width: 100vw;
		height: 100vh;
		
		.main{
			padding: 0 30rpx;
			box-sizing: border-box;
			padding-bottom: 200rpx;
			
			// 审核中
			.status1{
				background-color: #eee8d6;
				border: 2rpx solid #E6A23C;
			}
			// 通过审核
			.status2{
				background-color: #DEF9F0;
				border: 2rpx solid #03CD8E;
			}
			// 审核不通过
			.status3{
				background-color: #e2e2e2;
				border: 2rpx solid #8f8f8f;
			}
			// 使用中
			.currentItem{
				background-color: #98f9de;
				border: 2rpx solid #01b47b;
			}
			.store_box{
				width: 100%;
				display: flex;
				flex-direction: column;
				box-sizing: border-box;
				padding-bottom: 60rpx;
				border-radius: 30rpx;
				margin-bottom: 30rpx;
				position: relative;
				
				.currentStore{
					color: #fff;
					font-size: 26rpx;
					position: absolute;
					top: 0;
					left: 0;
					
					.auditing{
						background-color: #E6A23C;
						border-top-left-radius: 30rpx;
						border-bottom-right-radius: 30rpx;
						padding: 8rpx 20rpx;
						color: #fff;
					}
					.success{
						background-color: #03CD8E;
						border-top-left-radius: 30rpx;
						border-bottom-right-radius: 30rpx;
						padding: 8rpx 20rpx;
						color: #fff;
					}
					.fail{
						background-color: #8f8f8f;
						border-top-left-radius: 30rpx;
						border-bottom-right-radius: 30rpx;
						padding: 8rpx 20rpx;
						color: #fff;
					}
					.current{
						font-size: 34rpx;
						font-weight: bold;
					}
				}
				
				.audit1{
					border-bottom: 2rpx solid #E6A23C;
				}
				.audit2{
					border-bottom: 2rpx solid #02ffaf;
				}
				.audit3{
					border-bottom: 2rpx solid #8f8f8f;
				}
				
				.title{
					width: 100%;
					padding-top: 60rpx;
					padding-bottom: 40rpx;
					display: flex;
					align-items: center;
					position: relative;
					padding-left: 30rpx;
					box-sizing: border-box;
					// border-bottom: 2rpx solid #02ffaf;
						
					.left{
						height: 60rpx;
						display: flex;
						align-items: center;
						color: #03CD8E;
						font-size: 40rpx;
						font-weight: bold;
					}
					
					.right{
						height: 50rpx;
						border-bottom-left-radius: 25rpx;
						border-top-left-radius: 25rpx;
						position: absolute;
						right: 0;
						display: flex;
						justify-content: space-between;
						align-items: center;
						color: #fff;
						background: linear-gradient(to right, #03CD8E, #02ffaf);
						font-size: 30rpx;
						
						.icon{
							height: 50rpx;
							width: 50rpx;
							background-color: #DEF9F0;
							border-radius: 50%;
							display: flex;
							justify-content: center;
							align-items: center;
							background-color: #03CD8E;
							// box-shadow: inset 5rpx 5rpx 10rpx 5rpx rgba(255, 255, 255, 0.3);
							background: linear-gradient(to right, #03CD8E, #02ffaf);
						}
						
						text{
							padding: 0 16rpx;
						}
					}
				}
				.content{
					display: flex;
					flex-direction: column;
					padding: 0 30rpx;
					font-size: 30rpx;
					
					.item{
						margin-top: 40rpx;
						position: relative;
					}
				}
			}
			
		}
		.bottom_submit{
			width: 100%;
			position: fixed;
			bottom: 0;
			left: 0;
			padding: 0 30rpx;
			padding-bottom: env(safe-area-inset-bottom);
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: #fff;
			
			.button{
				width: 100%;
				height: 80rpx;
				border-radius: 35rpx;
				font-size: 28rpx;
				color: #fff;
				padding: 0;
				font-size: 34rpx;
				font-weight: bold;
				margin-top: 30rpx;
				
				text{
					padding: 0 10rpx;
				}
			}
		}
		
	}
</style>
